package com.example.dormitory.service;

import com.example.dormitory.entity.Absent;
import com.example.dormitory.mapper.AbsentMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class AbsentService {

    @Autowired
    private AbsentMapper absentMapper;

    public int create(Absent absent) {
        return absentMapper.create(absent);
    }

    public int delete(String ids) {
        String[] arr = ids.split(",");
        int row = 0;
        for (String s : arr) {
            if(!StringUtils.isEmpty(s)){
                absentMapper.delete(Integer.parseInt(s));
            row++;
            }
        }
        return row;
    }

    public int delete(Integer id) {
        return absentMapper.delete(id);
    }

    public int update(Absent absent) {
        return absentMapper.update(absent);
    }

    public int updateSelective(Absent absent) {
        return absentMapper.updateSelective(absent);
    }

    public PageInfo<Absent> query(Absent absent) {
        if(absent != null && absent.getPage() != null){
            PageHelper.startPage(absent.getPage(),absent.getLimit());
        }
        return new PageInfo<Absent>(absentMapper.query(absent));
    }

    public Absent detail(Integer id) {
        return absentMapper.detail(id);
    }

    public int count(Absent absent) {
        return absentMapper.count(absent);
    }
}
